package com.lwl.service.impl.sas;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.dao.sas.TSasRecordMapper;
import com.lwl.entity.*;
import com.lwl.entity.sas.SasTongji1;
import com.lwl.entity.sas.SasTongji2;
import com.lwl.entity.sas.TSasRecord;
import com.lwl.service.sas.TSasRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class TSasRecordServicelmpl implements TSasRecordService {
    @Autowired
    private TSasRecordMapper tSasRecordDao;

    @Override
    public PageInfo queryAll(MyPage myPage, TSasRecord tSasRecord) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<TSasRecord> tSasRecords = tSasRecordDao.queryAll(tSasRecord);
        PageInfo pageInfo = new PageInfo(tSasRecords);
        return pageInfo;
    }

    @Override
    public TSasRecord checkRecord(TSasRecord tSasRecord) {
        TSasRecord tSasRecord1 = tSasRecordDao.selectOne(tSasRecord);
        return tSasRecord1;
    }

    @Override
    public int insertRecord1(TSasRecord tSasRecord) {
        tSasRecord.setCreatetime(new Date());
        int insert = tSasRecordDao.insert(tSasRecord);
        Example example = new Example(TSasRecord.class);
        example.createCriteria().andEqualTo("tel",tSasRecord.getTel());
        List<TSasRecord> tSasRecords = tSasRecordDao.selectByExample(example);
        TSasRecord tSasRecord1 = tSasRecords.get(0);
        return tSasRecord1.getId();
    }

    @Override
    public PageInfo recordDetails(Integer id, MyPage myPage) {
        PageHelper.startPage(myPage.getPage(), myPage.getLimit());
        List<Map<String,Object>> recordDetailList = tSasRecordDao.queryRecordDetail(id);
        PageInfo pageInfo = new PageInfo(recordDetailList);
        return pageInfo;
    }

    @Override
    public PageInfo getStatistics2(MyPage myPage, SasTongji2 sasTongji2) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        PageInfo pageInfo = new PageInfo(tSasRecordDao.getStatistics2(sasTongji2));
        return pageInfo;
    }

    @Override
    public List<SasTongji1> getStatistics1() {
        List<SasTongji1> sasTongji1List = tSasRecordDao.getStatics1();
        return sasTongji1List;
    }



}
